import React, { Component } from 'react'
import Header from '../../components/Header/Header'
import Banner from "./components/Banner/Banner"
import Newbie from "./components/Newbie/Newbie"
import Groupon from "./components/Groupon/Groupon"
import Tindexgoods from './components/Tindexgoods/Tindexgoods'
import "./Home.less"
import {
  reqgetbanner,
  reqgetnew,
  reqgetgroupon,
  reqgetindexgoods
} from "../../http/api"




export default class Home extends Component {
  constructor() {
    super()
    this.state = {
      newarr: [],
      groupon: [],
      bannerarr: [],
      tindexgoods: [],
      n:0

    }

  }

  componentDidMount() {
    this.getbanner()
    this.getNewbie()
    this.getgroupon()
    this.gettindexgoods()
  }

  //轮播图
  async getbanner() {
    let res = await reqgetbanner();
    if (res.data.code == 200) {
      this.setState({
        bannerarr: res.data.list ? res.data.list : []
      })
    }
  }

  //新人专享
  async getNewbie() {
    let res = await reqgetnew();
    if (res.data.code == 200) {
      this.setState({
        newarr: res.data.list ? res.data.list : []
      })
    }
  }

  //万人团
  async getgroupon() {
    let res = await reqgetgroupon();
    if (res.data.code == 200) {
      this.setState({
        groupon: res.data.list ? res.data.list : []
      })
    }
  }

  //商品信息首页
  async gettindexgoods() {
    let res = await reqgetindexgoods();
    if (res.data.code == 200) {
      this.setState({
        tindexgoods: res.data.list ? res.data.list : []
      })
    }
  }



  render() {
    let { bannerarr, newarr, groupon, tindexgoods ,n} = this.state

    return (
      <div>
        <Header register title="首页"></Header>
        <div className='box'>
          <Newbie newarr={newarr}></Newbie>
          <Banner bannerarr={bannerarr}></Banner>
          <Groupon groupon={groupon}></Groupon>
          <Tindexgoods tindexgoods={tindexgoods} n={n} onChangeN={n=>{this.setState({
            n
          })}}></Tindexgoods>

        </div>

      </div>
    )
  }
}
